package homework06;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class TCPServer {
	public static void main(String[] args) throws Exception {
		ServerSocket server = new ServerSocket(8002);
		Socket socket = server.accept();

		InputStreamReader reader = new InputStreamReader(socket.getInputStream());
		BufferedReader buffer_reader = new BufferedReader(reader);
		PrintWriter writer = new PrintWriter(socket.getOutputStream());

		String request = buffer_reader.readLine();

		System.out.println("Client say:" + request);

		String line = "Hello, world!";
		writer.println(line);
		writer.flush();

		writer.close();
		buffer_reader.close();
		socket.close();
		server.close();
	}
}
